const express = require('express')
const router = express.Router()
const { addCondition,getCondition,deleteCondition,updateCondition } = require('../services/ConditionService')

// 新增
router.post('/', async (req, res) => {
  console.log(req.body)
  const result = await addCondition(req.body)
  if(result){
    res.status(200).json({
      msg: '报告成功',
      code: 1,
    })

  }else{[
    res.status(404).json({ msg: '报告失败', code: 0 })
  ]} 
})
//获取
router.get('/', async (req, res) => {
  const result = await getCondition()
  
  res.send({
    msg: "路况信息",
    data: result,
    code: 1,
  });
})
//删除
router.delete('/', async (req, res) => {
  const result = await deleteCondition(req.query.id)
  if(result){
    res.send({ msg: "删除成功", code: 1 });
  }else{
    res.send({ msg: "删除失败", code: 0 });
  }

})
//更新
router.put('/', async (req, res) => {
  console.log(req.body.id)
  const result = await updateCondition(req.body.id)

   if(result){
     res.send({ msg: "更新成功", code: 1 });
   }else{
     res.send({ msg: "更新失败", code: 0 });
   }
  
})


module.exports = router
